package com.ironman.original.generator;


import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PostureOriginalDataGenerator extends OriginalDataGenerator {

    @Override
    public String dataType() {
        return "posture";
    }

    @Override
    public String generate() {
        Integer randomEle1 = RandomUtil.randomEle(new Integer[]{-180, 180});
        Integer randomEle2 = RandomUtil.randomEle(new Integer[]{-180, 180});
        return random(randomEle1) + "," + random(randomEle2);
    }

    @Override
    public void log(Boolean published, String data) {
        log.info("posture: {}\n{}", published, data);
    }

    private String random(Integer randomEle) {
        double minInclude;
        double maxExclude;
        if (randomEle > 0) {
            minInclude = 0;
            maxExclude = randomEle;
        } else {
            minInclude = randomEle;
            maxExclude = 0;
        }
        return StrUtil.format("{}|{}|{}|{}|{}|{}|{}|{}|{}|{}",
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue(),
                NumberUtil.round(RandomUtil.randomDouble(minInclude, maxExclude), 3).doubleValue()
        );
    }
}
